<?
// LATER WE MOVE THESE AWAY;
class item{
	//name="id_user" description="ID" type="int" length="" extra="autonumber" null="no" default="no"
	var $name;
	var $description;
	var $type;
	var $length;
	var $extra;
	var $canBeNull;
	var $defaultVal;
	var $index;
	var $fulltext;
	var $display;
	var $attribute;
	function item($ar){
		$this->name=$ar["attributes"]["name"];
		$this->description=$ar["attributes"]["description"];
		$this->type=$ar["attributes"]["type"];
		$this->length=$ar["attributes"]["length"];
		$this->extra=$ar["attributes"]["extra"];
		$this->canBeNull=$ar["attributes"]["null"];
		$this->defaultVal=$ar["attributes"]["default"];
		$this->index=$ar["attributes"]["index"];
		$this->fulltext=($ar["attributes"]["fulltext"]=="yes"?true:false);
		$this->attribute=$ar["attributes"]["attribute"];
		if (is_array($ar[0])){
			foreach($ar[0] as $disp)
				$this->display=new display($disp);
		}else{
			$this->display=new display(array("attributes"=>array("type"=>"text")));
		}

	}
}
class display{
	var $type;
	var $options;
	function display($ar){
		//print_r($ar);
		
// 		print_r($ar);echo "<HR>";
		$this->type = $ar["attributes"]["type"];
		foreach($ar as $op){
			if (key($op)!="attributes"){
				$this->options=new options($op["option"]);
			}
		}
		
	}
}
class option{
}
class options{
	var $order;
	var $value;
	var $description;
	var $default;
	var $selected;
	var $class;
	function options($ar){
//		print_r($ar);echo "<HR>";
		if (is_array($ar["attributes"])){
			$this->order=$ar["attributes"]["order"];
			$this->value=$ar["attributes"]["value"];
			$this->description=$ar["attributes"]["description"];
			$this->default=$ar["attributes"]["default"];
			$this->selected=(isset($ar["attributes"]["selected"])?true:false);
			$this->class=(isset($ar["attributes"]["class"])?$ar["attributes"]["class"]:"input");
		}else{
			$this->order="";
			$this->value="";
			$this->description="";
			$this->default="";
			$this->selected=false;;
			$this->class="input";
		}
	}
}
class values{
	var $vars;
	function values($ar){
		$this->vars=array();
		//print_r($ar);
		foreach ($ar as $vars){
			if (key($vars)!="attributes"&&key($vars)!=""){
				$this->vars[]=new item($vars["item"]);
			}
		}
	}
}
class module{
	var $name;
	var $description;
	var $values;//array of values
	function module($ar){
		$this->name=$ar["attributes"]["name"];
		if (isset($ar[0]["description"])){
			$this->description=$ar[0]["description"][0];
			$this->values=new values($ar[1]["variables"]);
		}else{
			echo "MODULE [".$this->name."] WITHOUT DESCRIPTION DETECTED<BR>";
			$this->values=new values($ar[0]["variables"]);
		}
		// INDEXES
		//$this->values=new values($ar[1]["variables"]);
	}
}
class modules{
	var $mods;
	function modules($ar){
		$this->mods=array();
		foreach($ar as $mod){
			if (key($mod)!="attributes"&&key($mod)!=""){
				$this->mods[]=new module($mod["module"]);
			}
		}
	}
}

class config{
	
	var $php_classes;
	var $php_admin;
	var $mysql_tables;
	var $mysql_drop;
	var $mysql_ifexists;
	var $mysql_table_prefix;
	var $styles;

	function config($arr){
		foreach($arr as $internal){
			switch(key($internal)){
			case "php":
				$this->php($internal["php"]);
				break;
			case "mysql":
				$this->mysql($internal["mysql"]);
				break;
			case "styles":
				$this->styles($internal["styles"]);
				break;
			}
		}
	}
	function php($ar){
		$this->php_classes=$ar["attributes"]["classes"]=="yes"?true:false;
		$this->php_admin=$ar["attributes"]["admin"]=="yes"?true:false;
	}
	function mysql($ar){
		$this->mysql_tables=$ar["attributes"]["tables"]=="yes"?true:false;
		$this->mysql_drop=$ar["attributes"]["drop"]=="yes"?true:false;
		$this->mysql_ifexists=$ar["attributes"]["ifexists"]=="yes"?true:false;
		$this->mysql_table_prefix=$ar["attributes"]["table_prefix"];
	}
	function styles($ar){
		$this->styles="";
		foreach ($ar as $keystyle){
			if (key($keystyle)!=""){
			$this->styles.="\t.".key($keystyle)."{".$keystyle[key($keystyle)][0]."}\n";
			}
		}
	}
}
?>